<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="info-Customer">
    <label for="categoryId">分类</label>
    <input id="categoryId" class="easyui-combobox" data-options="valueField:'id',textField:'name',method:'get',url:'api/people/category'"/>
    <label for="code">编码</label>
    <input id="code" class="easyui-combobox" data-options="valueField:'code',textField:'code',method:'get',url:'api/people/customer/getCode'"/>
    <label for="name">名称</label><input type="text" id="name" name="name"/>
    <em><a id="search" href="#" class="easyui-linkbutton"data-options="iconCls:'icon-search'">查询</a></em>
    <i><a id="add" href="#" class="easyui-linkbutton"data-options="iconCls:'icon-add'">添加</a></i>
    <b><a id="reload" href="#" class="easyui-linkbutton"data-options="iconCls:'icon-reload'">刷新</a></b>
    <table id="customerGrid"></table>
</div>
<div id="customerAddDialog"></div>
<div id="customerDialog"></div>
<input type="hidden" name="customerId" id="customerId">
<style>
    .datagrid-header-row {
        background-color: #4dded8;
    }
</style>
<script>
    (function () {
        var table = $('#customerGrid');
        table.datagrid({
            height: ($(window).height()*0.9),
            url:'api/people/customer',
            method: 'get',
            striped: true,
            fitColumns: true,
            singleSelect: true,
            pagination: true,
            pageSize: 15,
            pageList: [15,25,35,50,70],
            columns: [[

                { field: 'code', title: '客户编码', align: 'center' },
                { field: 'categoryId', title: '客户分类',  align: 'center',
                    formatter:function(value,rowData,index) {
                        if (rowData.categoryId != null) {
                            return rowData.categoryName;
                        }
                    }
                },
                { field: 'name', title: '客户名称',  align: 'center'},
                { field: 'contact01', title: '联系人',  align: 'center'},
                { field: 'tel01', title: '手机', align: 'center' },
                { field: 'mobile01', title: '电话', width: 50, align: 'center' },
                { field: 'address', title: '地址',  align: 'center',},
                { field: 'addressReceipt', title: '收货地址',  align: 'center' },
                { field: 'initPayables', title: '应收期初余额',  align: 'center' },
                { field: 'initPayablesDt', title: '应收期初余额日期',  align: 'center' ,},
                { field: 'bankName', title: '开户行', align: 'center' },
                { field: 'taxNumber', title: '税号',width:50, align: 'center' },
                { field: 'fax', title: '传真',width:50, align: 'center' },
                { field: 'act', title: '操作', width: 50, align: 'center' ,
                    formatter:function(value,rowData,index){
                        return '<a del-customer id="' + rowData.id + '" href="javascript:;" >删除</a> ';
                    }
                }
            ]],
            loadFilter: function (data) {
                if(data != null ){
                    return data.data;
                }
            },onDblClickRow :function(rowIndex,rowData){
                var jsonObj=table.datagrid('getSelected');
                $("#customerId").val(JSON.stringify(jsonObj));
                $('#customerDialog').dialog({
                    title: '商品编辑',
                    width: 900,
                    height: 500,
                    closed: false,
                    cache: false,
                    href: 'page/customer-details',
                    modal: true
                });
            }
        });
        $('.info-Customer').on('click', 'em', function (e) {
            e.preventDefault();
            var categoryId=$('#categoryId').combobox('getValue');
            var code=$('#code').combobox('getValue');
            var name=$('input[name="name"]').val();
            e.stopPropagation();
            table.datagrid({
                url:'api/people/customer',
                method: 'get',
                queryParams:{categoryId:categoryId,code:code,name:name,page:"1",rows:"10"}
            });
        }).on('click','b',function (e) {
            e.preventDefault();
            e.stopPropagation();
            $('#categoryId').combobox('select','');
            $('#code').combobox('select','');
            $('input[name="name"]').val('');
            table.datagrid({
                url:'api/people/customer',
                queryParams:{page:"1",rows:"10"}
            });
        }).on('click','i',function(e){
            e.preventDefault();
            e.stopPropagation();
            $('#customerAddDialog').dialog({
                title: '添加客户',
                width: 900,
                height: 500,
                closed: false,
                cache: false,
                href: 'page/customer-add',
                modal: true
            });
        }).on('click','a[del-customer]',function(e){
            e.preventDefault();
            e.stopPropagation();
            var $this=$(this);
            var msg = "删除后无法恢复，您真的确定要删除吗？";
            if (confirm(msg)==true){
                $.ajax({
                    type: "delete",
                    url: "api/people/customer/"+$this.attr('id'),
                    success: function (data, status) {
                    	$.messager.show({
                    		title:'提示消息',
                    		msg: data.message,
                            timeout: 1000,
                            style: {
                                right: '',
                                bottom: ''
                            }
                    	});
                        table.datagrid('reload');
                    },error:function(data){
                        $.messager.alert('提示信息',data.responseJSON.message, 'warning');
                    }
                });
            }else{
                return false;
            }
        });
    })();
</script>
